package models;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;

import models.Workshop.DagDeel;

import org.junit.Before;
import org.junit.Test;



public class testWorkshop {
	String date_str = "2010-09-12";
	Date date;
	DagDeel dagDeel = DagDeel.VOORMIDDAG;
	Workshop workshop;
	
	@Before
	public void setup() throws ParseException {
		date = Workshop.parseDbDate(date_str);
		workshop = new Workshop(1, "title", date, dagDeel, 10.0, "explanation", 1, "docent");
	}
	
	@Test
	public void testWorkshopConstructor() {
		assertEquals("title", workshop.getTitle());
		assertEquals(date, workshop.getDate());
		assertEquals(dagDeel, workshop.getDagDeel());
		assertEquals(10.0,0.1, workshop.getPrice());
		assertEquals("explanation", workshop.getExplaination());
		assertEquals(1, workshop.getParticipantsMax());
		assertEquals("docent", workshop.getDocent());
	}
	@Test
	public void testWorkshopCopy() {
		Workshop workshopCopy = workshop.copy();
		assertEquals("title", workshopCopy.getTitle());
		assertEquals(date, workshopCopy.getDate());
		assertEquals(dagDeel, workshopCopy.getDagDeel());
		assertEquals(10.0,0.1, workshopCopy.getPrice());
		assertEquals("explanation", workshopCopy.getExplaination());
		assertEquals(1, workshopCopy.getParticipantsMax());
		assertEquals("docent", workshopCopy.getDocent());
	}
	
	@Test
	public void getId() {
		assertEquals(1, workshop.getId());
	}
	
	@Test
	public void test_getDataString() {
		assertEquals("title='title', date='" + date_str + "', dagdeel='VOORMIDDAG', price='10.0', explaination='explanation', participantsMax='1', docent='docent'",	workshop.getDataString());
	}
	
	@Test
	public void test_getSelectString() {
		
		assertEquals("title='title' AND date='" + date_str + "' AND dagdeel='VOORMIDDAG' AND price='10.0' AND explaination='explanation' AND participantsMax='1' AND docent='docent'",	workshop.getSelectString());
	}
	
	@Test
	public void testDataHeaders() {
		String[] lijst = {"title", "date", "dagdeel", "price", "explaination", "participantsMax", "docent"};
		assertEquals(Arrays.asList(lijst), Arrays.asList(workshop.getDataHeaders()));
	}
	
	@Test
	public void testGetData() {
		String[] lijst = {"title", date_str, ""+dagDeel, "10.0", "explanation", "1", "docent"};
		assertEquals(Arrays.asList(lijst), Arrays.asList(workshop.getData()));
	}
	
	@Test
	public void testSearchedMatch() {
		assertEquals(true, workshop.isSearchMatch("title"));
		assertEquals(true, workshop.isSearchMatch("10"));
		assertEquals(true, workshop.isSearchMatch("explanation"));
		assertEquals(false,workshop.isSearchMatch("ownroad"));
	}
	
	@Test
	public void testWorkshopIsSimilarTo() {
		//DagDeel dagdeel = DagDeel.HELEDAG;
		Date then = new Date();
		//Date later = new Date(2010, 10, 23);	//wat is deprecated en waarom hier?
		Workshop eneWorkshop = new Workshop ("Hello World", then, DagDeel.HELEDAG, 12.0, "Introductie", 3, "meneer Ouweneel");
		Workshop andereWorkshop = new Workshop ("Hello World", then, DagDeel.HELEDAG, 12.0, "Introductie", 3, "meneer Ouweneel");
		assertEquals( eneWorkshop.getTitle(), andereWorkshop.getTitle() );
		
		//Workshop date Nog testen bij verschillende Data
		assertEquals( eneWorkshop.getDate(), andereWorkshop.getDate() ); 
		
		assertEquals( eneWorkshop.getDagDeel(), andereWorkshop.getDagDeel() );
		
		//Delta=0 (3de argument) genomen voor prijs.
		assertEquals( eneWorkshop.getPrice(), andereWorkshop.getPrice(), 0 );
		
		assertEquals( eneWorkshop.getExplaination(), andereWorkshop.getExplaination() );
		assertEquals( eneWorkshop.getParticipantsMax(), andereWorkshop.getParticipantsMax());
		assertEquals( eneWorkshop.getDocent(), andereWorkshop.getDocent() );
	}
	
	@Test
	public void testEqualsAndHashCode() {
		// TODO see client
		fail();
	}
	
}